﻿using System;
using UniRx;
using UniRx.Triggers;
using UnityEngine;
using Valve.VR;

namespace Studio
{
	// Token: 0x020005E4 RID: 1508
	public class TouchpadRotation : MonoBehaviour
	{
		// Token: 0x170004BD RID: 1213
		// (get) Token: 0x06002689 RID: 9865 RVA: 0x000E14B8 File Offset: 0x000DF6B8
		private Transform transCamera
		{
			get
			{
				if (this.m_TransCamera == null)
				{
					this.m_TransCamera = this.objCameraRig.transform;
				}
				return this.m_TransCamera;
			}
		}

		// Token: 0x0600268A RID: 9866 RVA: 0x000E14E4 File Offset: 0x000DF6E4
		private bool CheckTouchAxis(TouchpadRotation.TouchAxis _axis)
		{
			Vector3 rhs = this.device.GetAxis(EVRButtonId.k_EButton_Axis0);
			switch (_axis)
			{
			case TouchpadRotation.TouchAxis.Up:
				return Vector3.Cross(new Vector3(1f, 1f, 0f), rhs).z >= 0f && Vector3.Cross(new Vector3(-1f, 1f, 0f), rhs).z <= 0f;
			case TouchpadRotation.TouchAxis.Down:
				return Vector3.Cross(new Vector3(1f, -1f, 0f), rhs).z <= 0f && Vector3.Cross(new Vector3(-1f, -1f, 0f), rhs).z >= 0f;
			case TouchpadRotation.TouchAxis.Left:
				return Vector3.Cross(new Vector3(-1f, 1f, 0f), rhs).z >= 0f && Vector3.Cross(new Vector3(-1f, -1f, 0f), rhs).z <= 0f;
			case TouchpadRotation.TouchAxis.Right:
				return Vector3.Cross(new Vector3(1f, 1f, 0f), rhs).z <= 0f && Vector3.Cross(new Vector3(1f, -1f, 0f), rhs).z >= 0f;
			default:
				return false;
			}
		}

		// Token: 0x0600268B RID: 9867 RVA: 0x000E1698 File Offset: 0x000DF898
		private void Rotation()
		{
			if (this.CheckTouchAxis(TouchpadRotation.TouchAxis.Right))
			{
				this.transCamera.Rotate(new Vector3(0f, 1f * (8f * Time.deltaTime), 0f));
			}
			if (this.CheckTouchAxis(TouchpadRotation.TouchAxis.Left))
			{
				this.transCamera.Rotate(new Vector3(0f, -1f * (8f * Time.deltaTime), 0f));
			}
		}

		// Token: 0x0600268C RID: 9868 RVA: 0x000E1714 File Offset: 0x000DF914
		private void Start()
		{
			this.device = SteamVR_Controller.Input((int)this.trackedObject.index);
			(from _ in this.UpdateAsObservable()
			where base.enabled
			where this.device.GetPress(4294967296UL)
			select _).Subscribe(delegate(Unit _)
			{
				this.Rotation();
			});
		}

		// Token: 0x04002691 RID: 9873
		[SerializeField]
		private GameObject objCameraRig;

		// Token: 0x04002692 RID: 9874
		private Transform m_TransCamera;

		// Token: 0x04002693 RID: 9875
		[SerializeField]
		private SteamVR_TrackedObject trackedObject;

		// Token: 0x04002694 RID: 9876
		private SteamVR_Controller.Device device;

		// Token: 0x020005E5 RID: 1509
		private enum TouchAxis
		{
			// Token: 0x04002696 RID: 9878
			Up,
			// Token: 0x04002697 RID: 9879
			Down,
			// Token: 0x04002698 RID: 9880
			Left,
			// Token: 0x04002699 RID: 9881
			Right
		}
	}
}
